package com.huilunyingshi.videoconsumer.controller;


import com.huilunyingshi.videoapi.service.TAnimeService;
import com.huilunyingshi.videoapi.service.TFilmService;
import com.huilunyingshi.videoapi.service.TTvSeriesService;
import com.hullunyingshi.until.ControllerResult;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

@Slf4j
@Scope("prototype")
@RestController
@RequestMapping("/Type")
public class AllTypeController {
    private final Logger logger = LoggerFactory.getLogger(FilmController.class);
    @Autowired
    private TFilmService tFilmService;
    @Autowired
    private TAnimeService tAnimeService;
    @Autowired
    private TTvSeriesService tTvSeriesService;

    //多类型查询所有
    @ApiOperation(value = "多类型查询", notes = "多类型查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Channel", value = "频道", paramType = "query", dataType = "String", required = false),
            @ApiImplicitParam(name = "LableName", value = "类型名称", paramType = "query", dataType = "String", required = false),
            @ApiImplicitParam(name = "ReleaseTime", value = "时间", paramType = "query", dataType = "String", required = false),
            @ApiImplicitParam(name = "area", value = "area类型", paramType = "query", dataType = "String", required = false),
            @ApiImplicitParam(name = "Status", value = "状态", paramType = "query", dataType = "String", required = false),
            @ApiImplicitParam(name = "Version", value = "版本", paramType = "query", dataType = "String", required = false),
            @ApiImplicitParam(name = "curPage", value = "当前页", paramType = "query", dataType = "int", required = false)
    })
    @GetMapping("getTypeLists")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "查询成功", response = ControllerResult.class),
            @ApiResponse(code = 400, message = "查询失败", response = String.class),
            @ApiResponse(code = 500, message = "(服务器内部错误)服务器遇到错误，无法完成请求 ", response = String.class),
    })
    public ControllerResult getTypeLists(String Channel, String LableName, String ReleaseTime, String area, String Status, String Version, Integer curPage) throws ParseException {
        try {
            if (Channel.equals("电视剧")) {
                return tTvSeriesService.getTvseriesTypeLists(LableName, ReleaseTime, area, Status, curPage);
            }

            if (Channel.equals("电影")) {
                return tFilmService.getFilmTypeLists(LableName, ReleaseTime, area, Status, curPage);
            }

            if (Channel.equals("动漫")) {
                return tAnimeService.getAnimeTypeLists(LableName, ReleaseTime, area, Version, Status, curPage);
            }
            return null;

        } catch (Exception e) {
            logger.info("#################### error 500 /getTypeLists" + e.getStackTrace());
            return new ControllerResult("500", "服务器错误", null);
        }
    }

}

